package main

import "fmt"

// 实例化结构体的方法

type P struct {
	name string
	age  int
}

func main() {
	//1
	var a = new(P)
	a.name = "A"
	a.age = 18
	fmt.Printf("%s is %d years old\n", a.name, a.age) // A is 18 years old

	//2
	var b = &P{
		name: "B",
		age:  18,
	}
	fmt.Printf("%s is %d years old\n", b.name, b.age) //B is 18 years old

	//3 常用
	var c P
	c.name = "C"
	c.age = 18
	fmt.Printf("%s is %d years old\n", c.name, c.age) //C is 18 years old

	//4
	var d = P{
		name: "D",
		age:  18,
	}
	fmt.Printf("%s is %d years old\n", d.name, d.age) //D is 18 years old

}
